<?php
/**
 * Mambot rd_readmore
 * @version $Id: rd_readmore.php,v 1.4 2005/12/20 15:10:16 deutz Exp $
 * @package RD_Readmore
 * @copyright Copyright (C) 2005 run-digital
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * 
 * @modified by Nikolai Plath - www.NiK-IT.de
 *
 * This is free software
 **/
 
 
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$_MAMBOTS->registerFunction( 'onPrepareContent', 'botReadMore' );



function botReadMore( $published, &$row, $params, $page=0  ) {
    if (!$published ) {
        return true;
    }

    global $mainframe, $database;

    $query = "SELECT id FROM #__mambots WHERE element = 'rd_readmore' AND folder = 'content'";//ADD - NiK
    $database->setQuery( $query );//ADD - NiK
    $id = $database->loadResult();//ADD - NiK
    $mambot = new mosMambot( $database );//ADD - NiK
    $mambot->load( $id );//ADD - NiK
    $botParams = new mosParameters( $mambot->params );//ADD - NiK
    $before_txt = $botParams->get( 'before_txt' );//ADD - NiK
    $after_txt  = $botParams->get( 'after_txt' );//ADD - NiK
    $title      = $botParams->get( 'title' );//ADD - NiK

    if ( $row->readmore  && $params->get( 'intro_only' )) {

        // get itemid if contentitem in menu
        $contentid = $row->id;
        $query = "select id from #__menu where published = '1' and type = 'content_item_link' and componentid='$contentid';";
        $database->setQuery( $query );
        $Itemid = $database->loadresult();
        
        if (!$Itemid) {
            // needed to reduce queries used by getItemid       
            $bs = $mainframe->getBlogSectionCount();
            $bc = $mainframe->getBlogCategoryCount();
            $gbs = $mainframe->getGlobalBlogSectionCount();
            // get Itemid
            $Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
        }    
        // Blank itemid checker for SEF
        if ($Itemid == NULL) {
            $Itemid = '';
        } else {
            $Itemid = '&amp;Itemid='. $Itemid;
        }

        if ($row->title_alias) {
            $linktext = $row->title_alias;
        } else {    
            $linktext = $before_txt . $row->title . $after_txt;//CHG - NiK
        } 
        $link = '<p><a href="'
          . sefRelToAbs( 'index.php?option=com_content&amp;task=view&amp;id='. $row->id . $Itemid ) 
          .'" class="readon" title="' . $title . $row->title . '">' . $linktext . '</a></p>';//CHG - NiK
        $row->text = $row->text . $link;
    }
    return true;
}
/** EOF **/
?>
